package com.example.b_308.software.view.main.message;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.b_308.software.R;
import com.example.b_308.software.model.MessageModel;

import java.util.List;

/**
 * Created by B-308 on 2017/11/22.
 */
public class MessageAdapter extends BaseAdapter {
  List<MessageModel> messageModels;
    LayoutInflater inflater;
    Context context;

    public MessageAdapter(List<MessageModel> messageModels,Context context) {
        super();
        this.messageModels=messageModels;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }

    //获取列表中条目的总数
    public int getCount() {
        return messageModels.size();
    }

    @Override
    //根据当前的第一个条目来获取对象
    public MessageModel getItem(int position) {

        return messageModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder viewHolder;
        if(null==convertView){
            View view=inflater.inflate(R.layout.item_message,null,false);
            viewHolder=new viewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(viewHolder) convertView.getTag();
            viewHolder.textView.setText(getItem(position).getStaff().getName());
        }
        return convertView;
    }

    public void notifyChange(List<MessageModel> messageModel) {
        this.messageModels=messageModel;
        notifyDataSetChanged();
    }

    class  viewHolder{
        View contentview;
        TextView textView;
        public viewHolder(View contentView){
            this.contentview=contentView;
            textView=(TextView) contentView.findViewById(R.id.tv_text);
        }
    }
}
